package org.mikrosopht.movievote.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class MovieListPager extends Composite implements ClickListener {

  private Button first = new Button("First");
  private Button previous = new Button("Previous");
  private Button next = new Button("Next");
  private Button last = new Button("Last");
  private HorizontalPanel pagerPanel = new HorizontalPanel();
  private MovieListPagerEventReceiver receiver;

  public MovieListPager(MovieListPagerEventReceiver receiver) {
    this.receiver = receiver;
    first = new Button("First", this);
    previous = new Button("Previous", this);
    next = new Button("Next", this);
    last = new Button("Last", this);
    pagerPanel.add(first);
    pagerPanel.add(previous);
    pagerPanel.add(next);
    pagerPanel.add(last);
    initWidget(pagerPanel);
  }

  public void setFirstDisabled() {
    first.setEnabled(false);
  }

  public void setPreviousDisabled() {
    previous.setEnabled(false);
  }

  public void setNextDisabled() {
    next.setEnabled(false);
  }

  public void setLastDisabled() {
    last.setEnabled(false);
  }

  public void setFirstEnabled() {
    first.setEnabled(true);
  }

  public void setPreviousEnabled() {
    previous.setEnabled(true);
  }

  public void setNextEnabled() {
    next.setEnabled(true);
  }

  public void setLastEnabled() {
    last.setEnabled(true);
  }

  public void onClick(Widget sender) {
    if (sender == first) {
      receiver.onFirstClick();
    } else if (sender == previous) {
      receiver.onPreviousClick();
    } else if (sender == next) {
      receiver.onNextClick();
    } else if (sender == last) {
      receiver.onLastClick();
    }
  }
}
